/**
 * 
 */
package com.thor.palmmall.rest.servicebill.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.SAttachmentConverter;
import com.thor.palmmall.rest.repair.converter.SWorkOrderConverter;
import com.thor.palmmall.rest.servicebill.AServiceBill;
import com.thor.palmmall.spi.servicebill.SServiceBill4Create;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SServiceBill4CreateConverter implements Converter<AServiceBill, SServiceBill4Create> {

  public static SServiceBill4CreateConverter getInstance() {
    if (instance == null)
      instance = new SServiceBill4CreateConverter();
    return instance;
  }

  private static SServiceBill4CreateConverter instance;

  private SServiceBill4CreateConverter() {
  }

  @Override
  public SServiceBill4Create convert(AServiceBill source) {
    if (source == null) {
      return null;
    }
    SServiceBill4Create target = new SServiceBill4Create();
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setContract(UCN.newInstance(source.getContract()));
    target.setServiceObject(source.getServiceObject());
    target.setContact(UCN.newInstance(source.getContact()));
    target.setContactInformation(source.getContactInformation());
    target.setServiceType(source.getServiceType());
    target.setProblemDescription(source.getProblemDescription());
    target.setAttachments(
        ConverterUtil.convert(source.getAttachments(), SAttachmentConverter.getInstance()));

    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    
    target.setType(source.getType());
    target.setWorkOrder(SWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    return target;
  }

}
